package znbkTestPaperXtfx.fragmentAdapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import znbkTestPaperXtfx.fragment.SystemReviewPaperFragment;

import static znbkTestPaperXtfx.activity.SystemReviewPaperActivity.mEntityXtfx;


/**
 * Created by Administrator on 2018\2\23 0023.
 */

public class SystemReviewPaperFragmentAdapter extends FragmentPagerAdapter {

    private long flag = 0;
    private FragmentManager fm;

    public SystemReviewPaperFragmentAdapter(FragmentManager fm) {
        super(fm);
        this.fm = fm;
    }
    @Override
    public int getCount() {
        int sumCount = 0 ;
        if(mEntityXtfx.getModelSinglePaperInfo() != null){
            sumCount = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().size();
        }
        return sumCount;
    }
    @Override
    public Fragment getItem(int position) {
        return SystemReviewPaperFragment.newInstance(position);
    }


    @Override
    public long getItemId(int position) {
        return position + flag;
    }

    public void paperHasSubmit(){
        flag = System.currentTimeMillis();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Fragment fragment = (Fragment) super.instantiateItem(container,
                position);
        fm.beginTransaction().show(fragment).commit();
        return fragment;
    }



    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        Fragment fragment = (Fragment) object;
        fm.beginTransaction().hide(fragment).commit();
    }
}